<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <div class="contentsize">委托单位管理</div>
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <!-- <div class="handle-box">
                <el-form ref="form" :model="form" label-width="auto" :inline="true" size="small">
                    <el-form-item label="单位名称:">
                        <div style="width:170px">
                            <el-input v-model="form.dwmc" placeholder="请输入单位名称" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="单位地址:">
                        <div style="width:170px">
                            <el-input v-model="form.dwdz" placeholder="请输入单位地址" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSearch" icon="el-icon-search" class="searchcolor">查询</el-button>
                        <el-button @click="reSearch" icon="el-icon-refresh" class="searchcolor">重置</el-button>
                    </el-form-item>
                </el-form>
            </div> -->
            <!-- max-height="310" -->
            <el-button type="primary" @click="addnew" icon="el-icon-plus" class="addcolor" size="small">添加</el-button>
            <el-table :data="tableData" style="width: 100%" :header-cell-style="tableHeaderColor"
                    :row-style="tablerowColor" :row-class-name="tableRowClassName" :cell-style="tablecellColor" border :max-height="maxHeight">
                <el-table-column prop="dwmc" label="单位名称" align="center" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="dwbh" label="单位编号" align="center"> </el-table-column>
                <el-table-column prop="dwdz" label="单位地址" align="center"> </el-table-column>
                <el-table-column prop="lxr" label="联系人" align="center"> </el-table-column>
                <el-table-column prop="lxdh" label="联系电话" align="center"> </el-table-column>
                <el-table-column fixed="right" label="操作" width="140" align="center">
                    <template slot-scope="scope">
                        <router-link :to="{ name: 'wtdwgldetail', params: { id: scope.row.id } }"
                            style="padding-right: 12px">
                            <el-button type="text" size="small">查看</el-button>
                        </router-link>
                        <router-link :to="{ name: 'wtdwgledit', params: { id: scope.row.id } }" style="padding-right: 12px">
                            <el-button type="text" size="small">编辑</el-button>
                        </router-link>
                        <el-button type="text" size="small" @click="deleteClick(scope.row)"
                            style="color: red">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination" style="float: right">
                <el-pagination background layout="total,prev, pager, next,jumper" :total="total" :current-page.sync="current"
                    :page-size="pageSize" @current-change="handleCurrentChange">
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { wtdwlist, wtdwlistdel } from '@/api/index';
import global from '@/components/common/httpurl.vue'
export default {
    name: 'wtdwgllist',
    data() {
        return {
            rules: {},
            // 请求表头信息
            myHeaders: {
                'token': localStorage.getItem('token')
            },
            filefileList: [],//文件列表
            httpUrl: global.httpUrl,//公共地址
            total: 0,
            current: 1,
            pageSize: 10,
            form: {
                create_time: '',//创建时间 ,
                current: 1,//第几页 ,
                dwbh: '',//单位编号 ,
                dwmc: '',//单位名称 ,
                id: '',//id ,
                lxdh: '',// 联系电话 ,
                lxr: '',//联系人 ,
                pageSize: 10,//每页数量 ,
                status_code: 1,//1正常 2删除
                tght: '',//托管合同 ,
                yyzz: '',//营业执照
            },
            tableData: [],
            maxHeight:null
        };
    },
    components: {},
    computed: {},
    methods: {
        // 列表样式
        tableHeaderColor({ row, column, rowIndex, columnIndex }) {
            if (rowIndex === 0) {
                return 'background:linear-gradient(to bottom, #008A94,#0ae2f2)!important;color:#ffffff;font-size:14px;'
            }
        },
        tablerowColor({ row, rowIndex }) {
            return 'height: 42px;font-size:14px;color:black'
        },
        tablecellColor(){
            return "font-weight:700;color:#000000;border-color:#c0c0c0";
        },
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 != 0) {
                return 'success-row' //这是类名
            } else {
                return ''
            }
        },
        // 换页
        handleCurrentChange(val) {
            this.current = val;
            this.form.current = val;
            this.wtdwlist(this.form);
            console.log(val);
        },
        // 搜索
        onSearch() {
            this.current = 1;
            this.form.current = 1;
            this.wtdwlist(this.form);
            console.log('搜索');
        },
        // 重置
        reSearch() {
            this.current = 1;
            this.form = {
                create_time: '',//创建时间 ,
                current: 1,//第几页 ,
                dwbh: '',//单位编号 ,
                dwmc: '',//单位名称 ,
                id: '',//id ,
                lxdh: '',// 联系电话 ,
                lxr: '',//联系人 ,
                pageSize: 10,//每页数量 ,
                status_code: 1,//1正常 2删除
                tght: '',//托管合同 ,
                yyzz: '',//营业执照
            };
            this.wtdwlist(this.form);
            console.log('搜索');
        },
        // 添加
        addnew() {
            this.$router.push({
                name: 'wtdwgladd',
                path: '/wtdwgladd'
            });
        },
        // 删除
        deleteClick(e) {
            console.log(e);
            this.$confirm('确定删除此条信息吗？')
                .then(() => {
                    let data = { id: e.id };
                    wtdwlistdel(data).then((res) => {
                        if (res.code == 200) {
                            this.wtdwlist(this.form);
                            this.$message.success('删除成功');
                        }
                    });
                })
                .catch(() => {
                    this.$message.success('删除取消');
                });
        },
        // 项目列表
        wtdwlist(data) {
            wtdwlist(data).then((res) => {
                if (res.code == 200) {
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                } else {
                    this.tableData = [];
                    this.total = 0;
                }
            });
        }
    },
    mounted() {
        this.$nextTick(() => {
            // window.innerHeight 浏览器窗口的可见高度，下面的 420 是除了table最大高度的剩余空间。
            this.maxHeight = window.innerHeight - 360
        })
        this.wtdwlist(this.form)
        console.log(this.$store.getters)
    }
};
</script>

<style scoped>
.container {
    /* height: calc(100vh - 260px); */
    overflow: hidden;
}

.crumbs {
    background-color: #fff;
    padding: 20px 20px;
}

.indexTitle {
    margin-bottom: 20px;
}

.contentsize {
    font-size: 18px;
    font-weight: 700;
}

.handle-box {
    overflow: hidden;
}

/* 新增按钮 */
.addcolor {
    margin-bottom: 10px;
}

.unloadTitle {
    text-align: left;
    padding-bottom: 10px;
    box-sizing: border-box;
    color: #606266;
}
</style>
<style>
.success-row {
    background-color: #eaf3fb !important;
}
</style>
